<?php

namespace App\Http\Controllers\Api;

use App\Http\Controllers\Controller;
use App\Rep\ModelRep;
use Illuminate\Http\Request;

class Model extends Controller
{
    protected $rep;

    public function __construct(Request $request)
    {
        $this->rep = new ModelRep();
    }



    /**
     * 获取模型列表
     * @param Request $request
     */
    public function getModelList(Request $request){
        $params = $request->all();
        $data = $this->rep->getModelListRep($params);
        if(isset($params['is_dropdown']) && !empty($params['is_dropdown'])){
            $data = $this->rep->getModelDropDownListRep($params);
        }
        return re(0,$data,'success');
    }

    /**
     * 添加模型
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function addModel(Request $request){
        $params = $request->all();
        $data = $this->rep->addModelRep($params);
        return re($data['code'],$data['data'],$data['msg']);
    }

    /**
     * 添加字段
     * @param Request $request
     */
    public function addModelField(Request $request){
        $params = $request->all();
        $data = $this->rep->addModelFieldRep($params);
        return re($data['code'],$data['data'],$data['msg']);
    }

    /**
     * 获取字段列表
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function getModelFieldList(Request $request){
        $params = $request->all();
        $data = $this->rep->getModelFieldListRep($params);
        return re($data['code'],$data['data'],$data['msg']);
    }

    /**
     * 默认字段显示设置
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function updateDefauleFieldShow(Request $request){
        $params = $request->all();
        $data = $this->rep->updateDefauleFieldShowRep($params);
        return re($data['code'],$data['data'],$data['msg']);
    }

    /**
     * 删除字段
     * @param Request $request
     */
    public function delModelField(Request $request){
        $params = $request->all();
        $data = $this->rep->delModelFieldRep($params);
        return re($data['code'],$data['data'],$data['msg']);
    }

    /**
     * 获取产品字段
     * @param Request $request
     */
    public function getProductFieldList(Request $request){
        $modelid = $request->input('modelid');
        $product_id = $request->input('product_id');
        $data = $this->rep->getProductFieldListRep($modelid,$product_id);
        return re(0,$data,'success');
    }









}
